package com.example.demo.controller;

import com.example.demo.common.domain.Employee;
import com.example.demo.service.DateService;
import com.example.demo.service.EmployeeService;
import com.example.demo.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class EmployeeController {
    @Autowired
    @Qualifier("es")
    private EmployeeService employeeService;


    @Autowired
    @Qualifier("recordServiceImpl")
    private RecordService recordService;



    public boolean check(HttpSession session){
        if(session.getAttribute("employee")!=null)
            return true;
        else
            return false;
    }
    @RequestMapping("/info")
    public String info(HttpSession session,Model model){//根据SESSION 用户ID值搜素用户并放入MODEL中，渲染到前端
        if(!check(session))
            return "login";
        Employee employee = (Employee) session.getAttribute("employee");
        model.addAttribute("employee",employee);
        return "info";
    }

//    @RequestMapping("/")
//    public String main(HttpSession session,Model model){//此处修改为不需要登录
//        Integer[] daysTable = dateService.getCalendarTable();
//        model.addAttribute("daysTable",daysTable);
//        return "cal";
//    }

    @RequestMapping("/index")
    public String index(HttpSession session,Model model){
        return "login";
    }

    @RequestMapping("/main")
    public String main2(HttpSession session,Model model){
        return "login";
    }






}
